<?php

/*

  Action	$3 +1 potion

  +2 Cards; +1 Action
  When you discard this from play, you may put this on top of your deck if you have a Potion in play.

 */

class Alchemist extends Card implements iAction, iKingdom, iAlchemy {

    public function __construct() {
        $price = new Price(3, 1);
        parent::__construct("Alchemist", $price);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+2 Cards",
            "+1 Action",
            "When you discard this from play, you may put this on top of your deck if you have a Potion in play.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addActions(1);
        $drawed_cards = $game->drawCards(2);
        ScreenDisplay::addScreenMessage($game, true, "get +1 action and draw " . nicePrint($drawed_cards), "gets +1 action and draws " . sizeof($drawed_cards) . " cards");
    }

    public function cleanup(Game $game) {
        $playArea = $game->getPlayArea();
        $potion = new Potion();
        $potion_found = false;
        foreach ($playArea as $card) {
            if ($card->getKey() == $potion->getKey()) {
                $potion_found = true;
                break;
            }
        }

        if ($potion_found) {
            $options = array(new Option(1, "Yes"), new Option(2, "No"));
            $output = MySocket::GetUserReply($game, Input_ChooseOne, $options, 1, 1, null, "Return alchemist on top of the draw deck?");
            $answer = $output[0];
            if ($answer == "Yes") {
                ScreenDisplay::addScreenMessage($game, true, "return ".  nicePrint($this)." on top of your deck ", "returns ".ScreenDisplay::$LMSG." on top of his deck");
                $game->moveCardFromPileToPile($this, PlayArea, DrawPile);
            } else {
                $game->moveCardFromPileToPile($this, PlayArea, DiscardPile);
            }
        }
        $game->cardCleanupFinished();
        return true;
    }

    public function boardSetup(Game $game) {
        $game->addPotion();
        return true;
    }

}

?>